package test;
import java.net.Socket;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Conn
{
   public static void main (String[] args) throws Exception {
		new Conn();
   }
   
   public Conn() throws Exception{
	   proxy.ClientProxy cp = new proxy.ClientProxy(4440, 4441);
	   
       Connection conn = null;
       String userName = "fire";
       String password = "safe";
       String url = "jdbc:mysql://127.0.0.1:4440/firesafe";
       conn = DriverManager.getConnection (url, userName, password);
       System.out.println ("Database connection established");
       
       Statement s = conn.createStatement();
       int count;
       s.executeUpdate("DROP TABLE IF EXISTS animal");
       s.executeUpdate("CREATE TABLE animal (id INT UNSIGNED NOT NULL AUTO_INCREMENT, PRIMARY KEY (id), name CHAR(40))");
       count = s.executeUpdate("INSERT INTO animal (name) values ('boll'),('katt'),('hund'),('traed')");
       s.close();
       System.out.println("c: "+ count);
       System.out.println("reset table animals with filling");
       
       s = conn.createStatement();
       s.executeQuery("SELECT * FROM animal");
       ResultSet rs = s.getResultSet();
       count=0;
       while (rs.next()) {
    	   System.out.println("namn: "+ rs.getString("name") +", id: "+ rs.getInt("id"));
       }
       rs.close();
       s.close();
       
       conn.close();
   }
   
}
